<?php

declare(strict_types=1);

namespace app\api\controller;

use app\common\model\User;
use app\common\model\District;
use app\common\model\DistrictPro;
use app\common\model\ProNature;
use app\common\model\ProPlace;
use app\common\model\Pro as ProModel;
use app\common\model\ProCate;
use app\common\model\ProTopic;
use app\common\model\CheckList;
use app\common\model\CheckListDetails;
use app\common\model\Company;
use app\common\model\ProRule;
use tecnickcom\tcpdf;
use app\common\model\CheckReport;

use think\exception\ValidateException;
use think\response\Json;

class Pro extends Base
{
    /**
     * 获取区域列表
     */
    public function getDistrict(): Json
    {
        $param = $this->request->get();
        try {
            $dist = District::where(['is_del' => 0])->order('sort asc')->select();
            if ($dist->isEmpty()) {
                return json(['code' => -1, 'msg' => '区域不存在！']);
            }
            return json(['code' => 1, 'msg' => '获取区域成功！', 'data' => $dist]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }
    /**
     * 获取区域下的项目场所
     */
    public function getProList(): Json
    {
        $param = $this->request->get();
        try {
            $dist = District::where(['id' => $param['district_id'], 'is_del' => 0])->find();
            if ($dist->isEmpty()) {
                return json(['code' => -1, 'msg' => '区域不存在！']);
            }
            $prolist = ProRule::where(['uid' => $this->user->id, 'is_del' => 0])->column('pro_id');
            if (empty($prolist)) {
                return json(['code' => -1, 'msg' => '您没有权限检查']);
            }
            $statuslist = [['type' => 0, 'title' => '正常', 'check' => 0], ['type' => 1, 'title' => '倒闭', 'check' => 0], ['type' => 2, 'title' => '已搬迁', 'check' => 0], ['type' => 3, 'title' => '责令停工停产', 'check' => 0], ['type' => 4, 'title' => '装修中/未营业', 'check' => 0], ['type' => 5, 'title' => '台账重复', 'check' => 0]];
            $list = DistrictPro::whereIn('pro_id', $prolist)->where(['district_id' => $param['district_id'], 'is_del' => 0])->order('sort asc')->select();
            // $list = ProModel::whereIn('id', $dist_pro)->where(['is_del' => 0])->order('sort asc')->select();
            return json(['code' => 1, 'msg' => '获取区域成功！', 'data' => $list, 'statuslist' => $statuslist]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }
    /**
     * 获取项目场所性质
     */

    public function getPlaceList(): Json
    {
        $param = $this->request->get();
        try {
            $infos = DistrictPro::where(['id' => $param['pro_id'], 'is_del' => 0])->find();
            $pro = ProModel::where(['id' => $infos['pro_id'], 'is_del' => 0])->find();
            if (empty($pro)) {
                return json(['code' => -1, 'msg' => '项目场所不存在！']);
            }
            $pro_nature = ProNature::where(['pro_id' => $infos['pro_id'], 'is_del' => 0])->column('place_id');
            $list = ProPlace::whereIn('id', $pro_nature)->where(['is_del' => 0])->order('sort asc')->select();
            return json(['code' => 1, 'msg' => '获取场所性质成功！', 'data' => $list]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }
    /**
     * 获取项目场所分类题目
     */

    public function getQueList(): Json
    {
        $param = $this->request->get();
        try {
            $infos = DistrictPro::where(['id' => $param['pro_id'], 'is_del' => 0])->find();
            $pro = ProModel::where(['id' => $infos['pro_id'], 'is_del' => 0])->find();
            if (empty($pro)) {
                return json(['code' => -1, 'msg' => '项目场所不存在！']);
            }
            $list = ProCate::where(['pro_id' => $infos['pro_id'], 'is_del' => 0])->field('id,pro_id,title,score,sort')->order('sort asc')->select();
            foreach ($list as $k => $v) {
                $child = ProTopic::where(['pro_id' => $infos['pro_id'], 'cate_id' => $v['id'], 'is_del' => 0])->field('id,title,pro_id,cate_id,desc,score,sort')->order('sort asc')->select();
                foreach ($child as $kk => $vo) {
                    if ($vo['desc'] != '') {
                        $vo['descs'] = explode(PHP_EOL, $vo['desc']);
                    } else {
                        $vo['descs'] = '';
                    }
                    $child[$kk] = $vo;
                }
                $v['child'] = $child;
                $list[$k] = $v;
            }
            return json(['code' => 1, 'msg' => '获取成功！', 'data' => $list]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }
    /**
     * 获取二检三检数据
     */

    public function getRecordList(): Json
    {
        $param = $this->request->get();
        try {
            $dist = District::where(['id' => $param['district_id'], 'is_del' => 0])->find();
            if (empty($dist)) {
                return json(['code' => -1, 'msg' => '区域不存在！']);
            }
            if (!empty($param['keyword']) && isset($param['keyword'])) {
                $ids = Company::whereLike('company_name', '%' . $param['keyword'] . '%')->where(['is_del' => 0])->column('id');
                $map[] = ['company_id', 'in', $ids];
            }
            $prolist = ProRule::where(['uid' => $this->user->id, 'is_del' => 0])->column('pro_id');
            if (empty($param['types'])) {
                $map[] = ['one_status', '=', 1];
            } else {
                if ($param['types'] == 1) {
                    $map[] = ['one_status', '=', 2];
                    $map[] = ['one_uid', '=', $this->user->id];
                } else {
                    $map[] = ['one_status', '>', 1];
                }
            }
            $map[] = ['district_id', '=', $param['district_id']];
            $map[] = ['is_del', '=', 0];
            $num = 20;
            $list = CheckList::getPageList($map, '*', $param['page'], 20, false);
            foreach ($list['data'] as $k => $v) {
                $status = '初检';
                $operstatus = '查看';
                if (!in_array($v['pro_id'], $prolist)) {
                    $v['rule'] = -1;
                } else {
                    $v['rule'] = 1;
                }
                $place_id=Company::where(['id' => $v['company_id'], 'is_del' => 0])->value('place_id');
                $v['status'] = $status;
                $v['operstatus'] = $operstatus;
                $v['idsort'] = ($k + 1) + ($num * $param['page'] - $num);
                $v['pro_name'] = DistrictPro::where(['id' => $place_id, 'is_del' => 0])->value('title');
                $v['company_name'] = Company::where(['id' => $v['company_id'], 'is_del' => 0])->value('company_name');
                $list['data'][$k] = $v;
            }
            return json(['code' => 1, 'msg' => '获取成功！', 'data' => $list]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }
    /**
     * 获取2检3检数据详情
     */

    public function getCheckDetails(): Json
    {
        $param = $this->request->get();

        try {
            $CheckList = CheckList::where(['id' => $param['check_list_id'], 'is_del' => 0])->find();
            if (empty($CheckList)) {
                return json(['code' => -1, 'msg' => '检查记录不存在！']);
            }
            $prolist = ProRule::where(['uid' => $this->user->id, 'is_del' => 0])->column('pro_id');
            if (!in_array($CheckList['pro_id'], $prolist)) {
                return json(['code' => -1, 'msg' => '您没有权限检查！']);
            }
            $company = Company::where(['id' => $CheckList['company_id'], 'is_del' => 0])->find();
            $statuslist = [['type' => 0, 'title' => '正常', 'check' => 0], ['type' => 1, 'title' => '倒闭', 'check' => 0], ['type' => 2, 'title' => '已搬迁', 'check' => 0], ['type' => 3, 'title' => '责令停工停产', 'check' => 0], ['type' => 4, 'title' => '装修中/未营业', 'check' => 0], ['type' => 5, 'title' => '台账重复', 'check' => 0]];
            if ($CheckList['one_status'] == 1) {
                $company['statusname'] = '未检';
                $company['statuslist'] = $statuslist;
                $company['times'] = '';
            } else {
                $company['statusname'] = '已检/' . User::where(['id' => $CheckList['one_uid'], 'is_del' => 0])->value('nickname');
                foreach ($statuslist as $k => $v) {
                    if ($company['status'] == $v['type']) {
                        $statuslist[$k]['check'] = 1;
                    }
                }
                $company['statuslist'] = $statuslist;
                $company['times'] = date('Y-m-d', strtotime($CheckList['one_time']));
            }
            $company['pro_name'] = DistrictPro::where(['id' => $company['place_id'], 'is_del' => 0])->value('title');
            if (!empty($company['images'])) {
                $company['imageslist'] = explode(',', $company['images']);
            } else {
                $company['imageslist'] = '';
            }
            $list = ProCate::where(['pro_id' => $CheckList['pro_id'], 'is_del' => 0])->field('id,pro_id,title,score,sort')->order('sort asc')->select();

            foreach ($list as $k => $v) {
                $child = ProTopic::where(['pro_id' => $CheckList['pro_id'], 'cate_id' => $v['id'], 'is_del' => 0])->field('id,title,pro_id,cate_id,desc,score,sort')->order('sort asc')->select();
                foreach ($child as $kk => $vv) {
                    $checkDetail = CheckListDetails::where(['is_del' => 0, 'check_list_id' => $CheckList['id'], 'topic_id' => $vv['id'], 'district_id' => $CheckList['district_id']])->find();
                    if ($checkDetail) {
                        $vv['status'] = 1;
                        $score = ProTopic::where(['id' => $vv['id'], 'is_del' => 0])->value('score');
                        $fenshu = $checkDetail['points'] - $score;
                        if ($fenshu > 0) {
                            $checkDetail['points'] = $fenshu;
                        } else {
                            $checkDetail['points'] = '';
                        }
                        $vv['checkDetail'] = $checkDetail;
                    } else {
                        $vv['status'] = 0;
                        $vv['checkDetail'] = '';
                    }
                    if ($vv['desc'] != '') {
                        $vv['descs'] = explode(PHP_EOL, $vv['desc']);
                    } else {
                        $vv['descs'] = '';
                    }
                    $child[$kk] = $vv;
                    if ($CheckList['types'] != 1) {
                        if ($vv['status'] == 0) {
                            unset($child[$kk]);
                        }
                    }
                }
                $v['child'] = $child;
                $list[$k] = $v;

                if ($CheckList['types'] != 1) {
                    if (count($v['child']) == 0) {
                        unset($list[$k]);
                    }
                }
            }

            $dangerCount = CheckListDetails::where(['is_del' => 0, 'check_list_id' => $CheckList['id'],  'district_id' => $CheckList['district_id']])->count();
            $zhenggai = CheckListDetails::where(['is_del' => 0, 'check_list_id' => $CheckList['id'],  'district_id' => $CheckList['district_id'], 'types' => 2])->count();
            //print('<pre>');print_r($list);die;
            return json(['code' => 1, 'msg' => '获取成功！', 'data' => ['zhenggai' => $zhenggai==0?-1:$zhenggai, 'one_status' => $CheckList['one_status'], 'list' => $list, 'dangerCount' => $dangerCount, 'one_score' => $CheckList['one_score'], 'one_uid_sign' => $CheckList['one_uid_sign'], 'one_company_sign' => $CheckList['one_company_sign'], 'company' => $company, 'types' => 1]]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }


    public function getReport(): Json
    {
        $param = $this->request->get();
        try {
            $CheckList = CheckList::where(['id' => $param['check_list_id'], 'is_del' => 0])->find();
            if (empty($CheckList)) {
                return json(['code' => -1, 'msg' => '还未进行检查，没有可输出的文件！']);
            }
            $list = CheckReport::where(['check_list_id' => $param['check_list_id']])->order('types asc')->select();
            foreach ($list as $k => $v) {
                if ($v['types'] == 1) {
                    $title = '检查报告';
                } else if ($v['types'] == 2) {
                    $title = '二检报告';
                } else if ($v['types'] == 3) {
                    $title = '三检报告';
                } else if ($v['types'] == 4) {
                    $title = '隐患清单';
                } else {
                    $title = '隐患复查清单';
                }
                $v['title'] = $title;
                $list[$k] = $v;
            }
            return json(['code' => 1, 'msg' => '获取成功！', 'data' => ['list' => $list]]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        } catch (\Exception $e) {
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }
    /**
     * 输出pdf
     */

    public function pdfpost(): Json
    {

        $param = $this->request->post('', '', $this->filter);

        try {
            $CheckList = CheckList::where(['id' => $param['check_list_id'], 'is_del' => 0])->find();
            if (empty($CheckList)) {
                return json(['code' => -1, 'msg' => '还未进行检查，没有可输出的文件！']);
            }

            $company = Company::where(['id' => $CheckList['company_id'], 'is_del' => 0])->find();
            $company['pro_name'] = ProModel::where(['id' => $company['pro_id'], 'is_del' => 0])->value('title');
            $company['place_name'] = ProPlace::where(['id' => $company['place_id'], 'is_del' => 0])->value('title');

            if ($CheckList['one_status'] == 1) {
                $company['statusname'] = '未检';
                $company['statuslistname'] = '未选择';
            } else {
                $company['statusname'] = '已检/' . User::where(['id' => $CheckList['one_uid'], 'is_del' => 0])->value('nickname');

                if ($company['status'] == 0) {
                    $names = '正常';
                } else if ($company['status'] == 1) {
                    $names = '倒闭';
                } else if ($company['status'] == 2) {
                    $names = '已搬迁';
                } else if ($company['status'] == 3) {
                    $names = '责令停工停产';
                } else if ($company['status'] == 4) {
                    $names = '装修中/未营业';
                } else {
                    $names = '台账重复';
                }
                $company['statuslistname'] = $names;
            }
            //分类列表
            // $list = ProCate::where(['pro_id' => $CheckList['pro_id'], 'is_del' => 0])->field('id,pro_id,title,score,sort')->order('sort asc')->select();

            // foreach ($list as $k => $v) {
            $child = ProTopic::where(['pro_id' => $CheckList['pro_id'],  'is_del' => 0])->field('id,title,pro_id,cate_id,desc,score,sort')->order('sort asc')->select();
            foreach ($child as $kk => $vv) {
                $checkDetail = CheckListDetails::where(['is_del' => 0, 'check_list_id' => $CheckList['id'], 'topic_id' => $vv['id'], 'district_id' => $CheckList['district_id'], 'types' => 1])->find();
                if ($checkDetail) {
                    $vv['status'] = 1;
                    $vv['checkDetail'] = $checkDetail;
                } else {
                    $vv['status'] = 0;
                    $vv['checkDetail'] = '';
                }
                $child[$kk] = $vv;
            }
            //     $v['child'] = $child;
            //     $list[$k] = $v;
            // }
            ///隐患列表
            $dangerList = CheckListDetails::where(['district_id' => $CheckList['district_id'], 'company_id' => $CheckList['company_id'], 'check_list_id' => $CheckList['id'], 'types' => 1, 'is_del' => 0])->order('topic_id asc')->select();
            if ($dangerList) {
                foreach ($dangerList as $k => $v) {
                    $v['topicname'] = ProTopic::where(['id' => $v['topic_id'], 'is_del' => 0])->value('title');
                    $dangerList[$k] = $v;
                }
            }
            $dangerCount = CheckListDetails::where(['district_id' => $CheckList['district_id'], 'company_id' => $CheckList['company_id'], 'check_list_id' => $CheckList['id'], 'types' => 1, 'is_del' => 0])->count();

            if ($param['types'] == 1) {
                $checkReport = CheckReport::where(['check_list_id' => $param['check_list_id'], 'types' => 1])->find();
                $title = '火灾隐患检查报告';
            } else {
                $checkReport = CheckReport::where(['check_list_id' => $param['check_list_id'], 'types' => 4])->find();
                $title = '火灾隐患清单';
            }

            $score = $CheckList['one_score'];
            $sign = $CheckList['one_uid_sign'];
            $companySign = $CheckList['one_company_sign'];

            $pdf = new \TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
            // 设置文档信息
            $pdf->SetTitle($title);
            $pdf->SetHeaderData('', 0, '', "", array(255, 255, 255), array(255, 255, 255));
            $pdf->setFooterData(array(0, 0, 0), array(0, 0, 0));
            $pdf->setHeaderFont(array('stsongstdlight', '', '12'));
            $pdf->setFooterFont(array('helvetica', '', '8'));
            $pdf->SetDefaultMonospacedFont('courier');
            $pdf->SetFooterMargin(10);
            $pdf->SetAutoPageBreak(TRUE, 25);
            $pdf->setImageScale(1);
            $pdf->setFontSubsetting(true);
            $pdf->setCellHeightRatio(1.75);
            $pdf->AddPage();
            $create_time = $CheckList['create_time'];
            $html = '
            <style>
              .yhtitle{width:20%;height:40px;line-height:40px;border-bottom:1px solid #333; border-right:1px solid #333;}
              .yhnr{width:30%;height:40px;line-height:40px;border-bottom:1px solid #333; border-right:1px solid #333;}
              .trtitle{width:20%;height:40px; line-height:40px; border-bottom:1px solid #333;}
              .trcontent{width:40%;height:40px;line-height:40px; border:1px solid #333; border-top:none;}
              .address{ font-size:12px;}
              .imsgestd{height:240px;position: relative; }
              .yimages{position: absolute;width:120px; hight:80px; display:block; }
              .tdh2{ width:100%; line-height:60px; font-weight:800; font-size:20px;}
              .trid{ width:5%;line-height:40px; border-bottom:1px solid #333; border-right:1px solid #333; }
              .thstatus{ width:15%;height:40px;line-height:40px;border-bottom:1px solid #333; border-right:1px solid #333;}
              .thtitle{ width:50%;height:40px;line-height:40px; border-bottom:1px solid #333; border-right:1px solid #333; font-size:13px;}
              .thdesc{ width:30%;height:40px;line-height:40px; border-bottom:1px solid #333; border-right:1px solid #333;}
              .thdescyh{ width:45%;height:40px;line-height:40px; border-bottom:1px solid #333; border-right:1px solid #333;}
              
              .red{ color:red;}
            </style>';
            $html .= '<table  align="centter" style="width=100%;">';
            $html .= '<tr>';
            $html .= '<td class="tdh2">' . $title . '</td>';
            $html .= '</tr>';

            if ($param['types'] == 1) {

                $html .= '<table  align="left" style="width=100%; height:300px; border:1px solid #333;"  valign="middle">';
                $html .= '<tr>';
                $html .= '<td class="trtitle">场所类别</td>';
                $html .= '<td class="trcontent">' . $company['pro_name'] . ' </td>';
                $html .= '<td class="trcontent"> 营业执照或门头图片</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">场所/单位名</td>';
                $html .= '<td class="trcontent">' . $company['company_name'] . '</td>';
                // $html .= '<td class="trcontent imsgestd" rowspan="6"> <img src="' . $company['images'] . '" class="yimages" /></td>';
                $html .= '<td class="trcontent imsgestd" rowspan="8">';
                $html .= '<img src="' . $company['images'] . '" class="yimages" />';
                //$pdf->Image($company['images'], '', '', 200, 200, '', '', 'center', false, '', 'C', false, false, 1, false, false, false);
                $html .= '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">地址</td>';
                $html .= '<td class="trcontent address" >' . $company['address'] . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">经营面积</td>';
                $html .= '<td class="trcontent">' . $company['area'] . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">建筑高度</td>';
                $html .= '<td class="trcontent">' . $company['height'] . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">消防负责人</td>';
                $html .= '<td class="trcontent">' . $company['fzname'] . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">联系电话</td>';
                $html .= '<td class="trcontent">' . $company['lxtel'] . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">检查日期</td>';
                $html .= '<td class="trcontent">' . $create_time . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">检查人</td>';
                $html .= '<td class="trcontent">' . $company['statusname'] . '</td>';
                $html .= '</tr>';
                $html .= '<tr>';
                $html .= '<td class="trtitle">异常状态</td>';
                $html .= '<td class="trcontent">' . $company['statuslistname'] . '</td>';
                $html .= '</tr>';

                $html .= '</table>';


                $html .= '<table  align="centter" style="width=100%;">';
                $html .= '<tr>';
                $html .= '<td class="tdh2">检查记录</td>';
                $html .= '</tr>';


                $html .= '<table  align="center" style="width=100%; border:1px solid #333;"  valign="middle">';

                $html .= '<tr  align="center">';
                $html .= '<td class="trid">序</td>';
                $html .= '<td class="thtitle" style="line-height:40px;">检查标准 </td>';
                $html .= '<td class="thstatus">合格状态</td>';
                $html .= '<td class="thdesc">不符合描述</td>';
                $html .= '</tr>';

                foreach ($child as $k => $v) {
                    $html .= '<tr>';
                    $html .= '<td class="trid">' . ($k + 1) . '</td>';
                    $html .= '<td class="thtitle">' . $v->title . '</td>';
                    if ($v['status'] == 1) {
                        $html .= '<td class="thstatus red">不合格</td>';
                        $html .= '<td class="thdesc">' . $v->checkDetail->desc . '</td>';
                    } else {
                        $html .= '<td class="thstatus">合格</td>';
                        $html .= '<td class="thdesc"></td>';
                    }
                    $html .= '</tr>';
                }
                $html .= '</table>';
            } else {



                $html .= '<table  align="center" style="width=100%; border:1px solid #333;"  valign="middle">';

                $html .= '<tr  align="center">';
                $html .= '<td class="trid">序</td>';
                $html .= '<td class="thtitle" style="line-height:40px;">不符合描述 </td>';
                $html .= '<td class="thdescyh">隐患图片</td>';
                $html .= '</tr>';

                foreach ($dangerList as $k => $v) {
                    $html .= '<tr>';
                    $html .= '<td class="trid">' . ($k + 1) . '</td>';
                    $html .= '<td class="thtitle">' . $v->topicname . '</td>';
                    $html .= '<td class="thdescyh"><img src="' . $v['images'] . '" class="yimages" /></td>';
                    $html .= '</tr>';
                }
                $html .= '</table>';
            }

            $pdf->SetFont('stsongstdlight', '', 14);

            $pdf->writeHTMLCell(0, 0, 10, 12, $html, 0, 1, 0, true, 'L', true);



            $pdf->AddPage();

            $htmlf = '
            <style>
              .yhtitle{width:20%;height:40px;line-height:40px;border-bottom:1px solid #333; border-right:1px solid #333;}
              .yhnr{width:30%;height:40px;line-height:40px;border-bottom:1px solid #333; border-right:1px solid #333;}
            </style>';

            $htmlf .= '<table  align="center" style="width=100%; border:1px solid #333;"  valign="middle">';
            $htmlf .= '<tr>';
            $htmlf .= '<td class="yhtitle">检查人员签名</td>';
            $htmlf .= '<td class="yhnr"><img src="' . $sign . '" style="width:60px; height:50px; display:block;"/></td>';
            $htmlf .= '<td class="yhtitle">被查单位确认</td>';
            $htmlf .= '<td class="yhnr"><img src="' . $companySign . '" style="width:60px; height:50px;  display:block;"/></td>';
            $htmlf .= '</tr>';

            $htmlf .= '</table>';


            $pdf->SetFont('stsongstdlight', '', 14);
            //$pdf->MultiCell(0, 5, $html, 0, 'L',false, 1, '', '',  true, 0,true,true);
            //$pdf->WriteHTML($html);
            $pdf->writeHTMLCell(0, 0, 10, 12, $htmlf, 0, 1, 0, true, 'L', true);


            ob_clean();
            $time = time();

            if (!empty($checkReport['pdfurl'])) {
                $pdf_path = $_SERVER['DOCUMENT_ROOT'] . $checkReport['pdfurl'];
                if (file_exists($pdf_path)) {
                    unlink('.' . $checkReport['pdfurl']);
                }
                $pdf_url_path = $checkReport['pdfurl'];
            } else {
                $pdf_path = $_SERVER['DOCUMENT_ROOT'] . '/file/' . $time . $param['check_list_id'] . '.pdf';
                $pdf_url_path = '/file/' . $time . $param['check_list_id'] . '.pdf';
            }
            if ($param['types'] == 1) {
                CheckReport::where(['check_list_id' => $param['check_list_id'], 'types' => $param['types']])->update(array('pdfurl' => $pdf_url_path));
            } else {
                CheckReport::where(['check_list_id' => $param['check_list_id'], 'types' => 4])->update(array('pdfurl' => $pdf_url_path));
            }
            //Makezip::zip('./file/','./zip'.'/'.time()."22.zip");

            $pdf->Output($pdf_path, 'F');
            // print_r($html);
            // die;
            return json(['code' => 1, 'msg' => '转成PDF成功！', 'url' => $pdf_url_path]);
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
    }

    /**
     * 查看pdf
     */

    public function pdfshowpost(): Json
    {
        $param = $this->request->post();
        try {
            return json(ProModel::pdfShow($param));
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
    }
}
